package com.harry.basis;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.harry.configuration.ConstSettings;

import lombok.Getter;
import lombok.Setter;

/**
 * 所有数据实体的基类
 * 1. 定义了共有的字段: id、createTime、updateTime
 * 2. 声明了一些常用数据类型常量
 */
@Getter
@Setter
@MappedSuperclass
public abstract class BasePoEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(length = ConstSettings.BASIC_LENGTH, insertable = false, updatable = false)
	@GeneratedValue(generator = "uuid2")
	@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
	private String id;

	@Column(columnDefinition = BasePoEntity.TIMESTAMP_FOR_CREATE, updatable = false, insertable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;

	@Column(columnDefinition = BasePoEntity.TIMESTAMP_FOR_UPDATE, insertable = false, updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date updateTime;

	public static final String TIMESTAMP_FOR_CREATE = "TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6)";

	public static final String TIMESTAMP_FOR_UPDATE = "TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)";

	public static final String DEFAULT_ZERO = "int NOT NULL DEFAULT 0";

	public static final String DEFAULT_FALSE = "BIT NOT NULL DEFAULT false";

	public static final String DEFAULT_TRUE = "BIT NOT NULL DEFAULT true";

	public static final String DEFAULT_DICT_PREFIX = "VARCHAR(32) NOT NULL DEFAULT ";

	public static final String DEFAULT_DICT_1 = DEFAULT_DICT_PREFIX + "'1'";

	public static final String TEXT_COLUMN = "TEXT";
}
